<template>
  <div>
    <van-nav-bar
        title="选座详情"
        left-arrow
        @click-left="goBack"
    />
    <van-cell-group :title="'选座编号:'+SeatSelection.id">
      <van-cell>
        <van-field label="图书馆" :value="SeatSelection.libraryName" readonly />
        <van-field label="楼层" :value="SeatSelection.floorNumber+'楼'" readonly />
        <van-field label="座位号" :value="SeatSelection.number" readonly />
        <van-field label="开始时间" :value="SeatSelection.start" readonly />
        <van-field v-if="SeatSelection.end.substr(11,8)!=='22:00:00'" label="结束时间" :value="SeatSelection.end" readonly />

      </van-cell>
      <van-cell>
        <van-button :disabled="returnSeatDisable" @click="returnSeatClick(SeatSelection.id)"
                    v-if="SeatSelection.end.substr(11,8)==='22:00:00'"
                    id="confirmBtn" type="danger" size="large">退座</van-button>
        <van-button v-else :disabled="deleteDisable" @click="deleteClick(SeatSelection.id)" type="danger" size="large">删除本条记录</van-button>
      </van-cell>

    </van-cell-group>

  </div>
</template>

<script>
import {returnSeat,deleteByIds} from "@/api/seat-selection";
import {Dialog} from "vant";

export default {
  data(){
    return{
      deleteDisable:false,
      deleteSeatIds:[],
      SeatSelection:this.$route.params,
      returnSeatIds:[],
      returnSeatDisable:false
    }
  },
  methods:{
    goBack(){
      this.$router.go(-1)
    },
    returnSeatClick(id){
      Dialog.confirm({
        title: '确定退座',
        message: '是否确定退座：['+this.SeatSelection.number+']',
      }).then(()=>{
        let params = new URLSearchParams();
        this.returnSeatIds = []
        this.returnSeatIds.push(id)
        params.append("ids",this.returnSeatIds);
        returnSeat(params).then(response=>{
          if(response.data!==0){
            Dialog.alert({
              title: '退座成功',
              message: '离开座位前请带好个人物品',
            })
          }
          this.returnSeatDisable = true
        })
      }) .catch(() => {
        // on cancel
      });

    },
    deleteClick(id){
      console.log(id)
      Dialog.confirm({
        title: '确定删除',
        message: '是否确定删除该记录',
      }).then(()=>{
        let params = new URLSearchParams();
        this.deleteSeatIds = []
        this.deleteSeatIds.push(id)
        params.append("ids",this.deleteSeatIds);
        deleteByIds(params).then(response=>{
          if(response.data!==0){
            Dialog.alert({
              title: '删除成功',
              message: '本记录已删除',
            })
          }
          this.deleteDisable = true
        })
      }) .catch(() => {
        // on cancel
      });
    }
  },

  name: "Details"
}
</script>

<style scoped>

</style>
